package xyz.twj.test.vertx;

import io.vertx.core.AbstractVerticle;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Source;

import java.time.ZoneId;
import java.util.Objects;

public class JsVertx extends AbstractVerticle {
    private static final Engine ENGINE = Engine.newBuilder().allowExperimentalOptions(true)
            .in(System.in).err(System.err).out(System.out).build();

    @Override
    public void start() throws Exception {
        System.out.println("start");
        try {
            Context context = Context.newBuilder("js")
                    .allowAllAccess(true)
                    .engine(ENGINE)
                    .build();
            Source source = Source.newBuilder("js", Objects.requireNonNull(
                            this.getClass().getClassLoader().getResource("index.js"), "cannot find js script"))
                    .build();
            context.eval(source);
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("xxxxx");
    }
}
